<template>
  <div class="buttonAdd">
    <!--<el-button type="primary" size="small" @click="dialogFormVisibleAdd = true">短信通知</el-button>-->
    <el-dialog :close-on-click-modal="false" :append-to-body="true"  title="短信通知" :visible.sync="dialogFormVisibleAdd" @opened="$store.commit('dialogTop')" @close="resetForm('ruleFormAdd')">
      <el-form :model="ruleFormAdd" :rules="rulesAdd" ref="ruleFormAdd" label-width="80px" class="demo-ruleForm">
        <el-form-item label="通知内容" prop="pushContent" :rules="[{ 'required':true, 'message': '请输入通知内容', 'trigger': 'blur' }]">
          <el-input
            type="textarea"
            :rows="3"
            :maxlength="70"
            placeholder="通知内容"
            v-model="ruleFormAdd.pushContent">
          </el-input>
        </el-form-item>
      </el-form>
      <div style="text-align: center;margin-bottom: 8px;margin-top: 15px;">
        <el-button type="primary" size="small" @click="submitForm('ruleFormAdd')">提 交</el-button>
        <el-button  size="small" @click="dialogFormVisibleAdd = false">取 消</el-button>
      </div>

    </el-dialog>
  </div>
</template>

<script>

  export default {
    props:[],
    data () {
      return {
        ruleFormAdd: {
          "userIds":[1],
          "pushContent":"",
        },
        streetData:[],
        dialogFormVisibleAdd: false,
        rulesAdd: {

        }
      }
    },
    created(){

    },
    methods: {
      dialogOpen(userIds){
        if(userIds.length==0){
          this.$message({
            type: 'warning',
            message: "请勾选要通知的人员"
          });
          return
        }

        this.ruleFormAdd.userIds=userIds
        this.dialogFormVisibleAdd=true
      },
      //提交回调
      handleDiaSureAdd(){
        this.axios.post(process.env.API_HOST + '/enterprise/notifyMessage', this.ruleFormAdd)
          .then(response => {
            let result=response.data
            if (result.code == 200) {
              this.$message({
                type: 'success',
                message: '发送成功!'
              });
              this.dialogFormVisibleAdd = false
              this.resetForm('ruleFormAdd')
            }

          })
          .catch(error => {
            console.log(error);
          });
      },
      submitForm(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            this.handleDiaSureAdd()
          } else {
            console.log('error submit!!');
            return false;
          }
        });
      },
      resetForm(formName) {
        this.$refs[formName].resetFields();
      }
    }
  }
</script>

<style lang="stylus" rel="stylesheet/stylus" >
  @import "../../../common/stylus/mixin.styl"
  .buttonAdd
    display inline-block
    margin-left 10px
</style>
